package com.zp.self.module.level_5_设计模式.结构型模式.Ⅴ_外观模式;

/**
 * @author ：by Zeng Peng
 * @date ：Created 2022/6/30 8:24
 * @description ：
 */
public class SmartApplianceFacade {

    public void monitorOrder(ApplianceType toolType, String order){
        if(!order.contains("on") && !order.contains("off")){
            System.out.println("未识别到正确指令~");
        }
        if(ApplianceType.All==toolType){
            ApplianceType[] values = ApplianceType.values();
            for (ApplianceType value : values) {
                if(value.getTool()!=null)
                    opreating(value.getTool(),order);
            }
        }else {
            opreating(toolType.getTool(),order);
        }
    }

    private void opreating(ElectricAppliance tool,String order){
        if(order.contains("on")){
            tool.on();
        }else {
            tool.off();
        }
    }
}
